package cn.da.shuai.cool.system.api.controller;

import cn.da.shuai.cool.common.entity.R;
import cn.da.shuai.cool.system.model.entity.dict.CoolDictData;
import cn.da.shuai.cool.system.service.service.ICoolDictDataService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 数据字典信息
 */
@RestController
@RequestMapping("/system/dict/data")
@Tag(name = "字典数据控制器")
public class CoolDictDataController {

    @Autowired
    private ICoolDictDataService dictDataService;

    @GetMapping("/list")
    @Operation(summary = "获取字典数据列表")
    public R<List<CoolDictData>> list(CoolDictData dictData) {
        List<CoolDictData> list = dictDataService.selectDictDataList(dictData);
        return R.ok(list);
    }

    @GetMapping("/page")
    @Operation(summary = "获取字典数据分页列表")
    public R<Page<CoolDictData>> page(CoolDictData dictData, Page<CoolDictData> page) {
        Page<CoolDictData> list = dictDataService.selectDictDataPage(dictData, page);
        return R.ok(list);
    }

    @GetMapping("/{dictCode}")
    @Operation(summary = "根据字典编码获取详细信息")
    public R<CoolDictData> getInfo(@PathVariable Long dictCode) {
        return R.ok(dictDataService.selectDictDataById(dictCode));
    }

    @GetMapping("/type/{dictType}")
    @Operation(summary = "根据字典类型查询字典数据信息")
    public R<List<CoolDictData>> dictType(@PathVariable String dictType) {
        List<CoolDictData> data = dictDataService.selectDictDataByType(dictType);
        return R.ok(data);
    }

    @PostMapping
    @Operation(summary = "新增字典数据")
    public R<Void> add(@RequestBody CoolDictData dict) {
        dictDataService.insertDictData(dict);
        return R.ok();
    }

    @PutMapping
    @Operation(summary = "修改字典数据")
    public R<Void> edit(@RequestBody CoolDictData dict) {
        dictDataService.updateDictData(dict);
        return R.ok();
    }

    @DeleteMapping("/{dictCodes}")
    @Operation(summary = "删除字典数据")
    public R<Void> remove(@PathVariable Long[] dictCodes) {
        dictDataService.deleteDictDataByIds(dictCodes);
        return R.ok();
    }
}